﻿using System;
using System.ComponentModel.Composition;
using Caliburn.Micro;
using Microsoft.Win32;

namespace CardPlay.Client.Tasks
{
    public class SelectFileTask : ISelectFileTask
    {
        public event EventHandler<ResultCompletionEventArgs> Completed;

        [Import]
        public IWindowManager WindowManager { get; set; }

        public string FileName { get; set; }

        public void Execute(ActionExecutionContext context)
        {
            var dialog = new OpenFileDialog();

            var result = dialog.ShowDialog();
            if (result == true) FileName = dialog.FileName;
           
            Completed(this, new ResultCompletionEventArgs { WasCancelled = result == false });
        }
    }
}